var tableIns;//表格实例
layui.use(['laydate','form','table'], function(){
    var form = layui.form;
    dict2Select("fieldType","externalType",/date/);
    dict2Select("fieldType","innerType");
    form.render();
    var laydate = layui.laydate;
    var table = layui.table;
    tableIns = table.render({
        elem: '#listTable'
        , url: appendCtx("/mm/fields")
        , page: true
        , even: true
        , cols: [[ //表头
            {field: 'id', title: 'ID',  align: 'center', width: 100},
            {field: 'innerEName', title: '英文名称', align: 'center',width: 140},
            {field: 'innerCName', title: '中文名称', align: 'center',width: 140},
            {field: 'externalType', title: '源类型', align: 'center',width: 100,templet:
            	function(d)
            	{
            		return translate("fieldType",d.externalType);
            	}
            },
            {field: 'innerType', title: '执行类型', align: 'center',width: 100,templet:
            	function(d)
            	{
            		return translate("fieldType",d.innerType);
            	}
            },
            {field: '', title: '是否必填', align: 'center',width: 100,templet:
            	function(d)
            	{
            		return translate("yesNo",d.notNull);
            	}
            },
            {field: '', title: '是否校验', align: 'center',width: 100,templet:
            	function(d)
            	{
            		return translate("yesNo",d.checkValue);
            	}
            },
            {field: 'description', title: '字段描述', align: 'center',width: 140},
            {field: 'createDate', title: '创建时间',align: 'center',width: 180},
            {field: 'creatorName', title: '创建人',align: 'center',width: 100},
            {title: '操作', align: 'center',width: 200,fixed:"right",toolbar: '#operBar'}
        ]]
        , request: {
            pageName: 'pageNo' //页码的参数名称，默认：page
            , limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        , parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.list //解析数据列表
                ,"attr":res.attr
            };
        }
    });
    form.on('submit(search)', function(formData){
        tableIns.reload({
            where:formData.field,
            page:{
                curr: 1
            }
        });
        return false;
    });
    
    form.on('submit(add)', function(){
    	layer.open({
            type: 2,
            title: '新增字段',
            area: ['1100px', '600px'],
            content: 'editField.html',
        });
        return false;
    });
});

function edit(id) {
    layer.open({
        type: 2,
        title: '修改字段',
        area: ['1100px', '600px'],
        content: 'editField.html?id=' + id,
    });
}

function detail(id) {
    layer.open({
        type: 2,
        title: '查看字段',
        area: ['1100px', '600px'],
        content: 'editField.html?detail=true&id=' + id,
    });
}

function refreshTableData() {
    tableIns.reload({});
}

function del(id){
	io.delete("/mm/fields/"+id,function(res){
		refreshTableData();
	});
}
